/**
 * Created by WYH on 17/2/22.
 */

/* 输入框是否有效的条件 */
var InputRule = (function () {

    function username(element) {
        var username = element.val();
        return (username.length < 4 || username.length > 20);
    }

    function password(element) {
        var password = element.val();
        return (password.length < 6 || password.length > 20);
    }

    function passwordDefference(passwordElement, rePasswordElement) {
        return passwordElement.val() == rePasswordElement.val()
    }
    
    function companyName(element) {
        var companyname = element.val();
        return (companyname.length < 4 || companyname.length > 40);
    }
    
    function companyAddress(element) {
        var address = element.val();
        return (address.length < 4 || address.length > 50);
    }
    
    function contactsName(element) {
        var contactName = element.val();
        return (!checkIsChineseOrEnglish(contactName) || contactName === "")
    }

    function fixedTelephone(element) {
        var telephone = element.val();
        var pattern = /^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;
        return telephone != "" && !pattern.test(telephone);
    }
    
    function mobileTelephone(element) {
        var mobilePhone = element.val();
        var pattern = /^1[3|4|5|7|8][0-9]{9}$/;
        return !(pattern.test(mobilePhone));
    }

    function email(element) {
        var email = element.val();
        var pattern = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
        return !(email == "" || pattern.test(email));
    }

    function staffName(element) {
        var staffName = element.val();
        return (checkIsChineseOrEnglish(staffName) && staffName.length >= 2 && staffName.length <= 20)
    }

    function idNumber() {
        var id = $(".staff_id").val();
        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        return !(reg.test(id));
    }
    

    function checkIsChineseOrEnglish(str) {
    for(var i = 0; i < str.length; i++) {
        if (!str[i].match("[a-zA-Z]") && !str[i].match("[\u4e00-\u9fa5]")) {
            return false
        }
    }
    return true;
}


    return {
        username: username,
        password: password,
        passwordDeference: passwordDefference,
        companyName: companyName,
        companyAddress: companyAddress,
        fixedTelephone: fixedTelephone,
        mobileTelephone: mobileTelephone,
        email: email,
        contactsName: contactsName,
        staffName:staffName,
        idNumber: idNumber
    }

})();